package com.study.minio.repository;

import com.study.minio.dao.mapper.OpenEmptyCardOrderMapper;
import com.study.minio.dao.model.OpenEmptyCardOrder;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Slf4j
@Repository
public class OpenEmptyCardOrderRepository {


    @Autowired
    private OpenEmptyCardOrderMapper openEmptyCardOrderMapper;


    public boolean insert(List<OpenEmptyCardOrder> list){
        if(Objects.isNull(list) || list.size() == 0){
            return true;
        }
        for(OpenEmptyCardOrder order : list){
            openEmptyCardOrderMapper.insert(order);
        }
        return true;
    }


    public boolean insertSql(List<String> list){
        if(Objects.isNull(list) || list.size() == 0){
            return true;
        }
        for(String sql : list){
            openEmptyCardOrderMapper.executeInsert(sql);
        }
        return true;
    }

    public boolean executeInsert(String paramSQL){
        return openEmptyCardOrderMapper.executeInsert(paramSQL)>0;
    }

    public Optional<OpenEmptyCardOrder> getBySysOrderId(String sysOrderId){
        return Optional.ofNullable(openEmptyCardOrderMapper.getBySysOrderId(sysOrderId));
    }


    public List<String> showColumns(String tableName){
        return openEmptyCardOrderMapper.showColumns("SHOW COLUMNS FROM "+tableName);
    }
}
